Skip to content

Setup.py file

Use the setup.py file to create a Python package. This file is used to install the package and its dependencies.

Alternative to requirements.txt, setup.py is a more powerful way to manage dependencies and environment.

Example

python
import setuptools

setuptools.setup(
    name="example",
    version="0.0.1",
    author="Author Name",
    author_email="",
    description="Description",
    long_description="Long description",
    long_description_content_type="text/markdown",
    url="https://example.com",
    packages=setuptools.find_packages(
        ".",
        include=("my_package", "my_package.*"),
    ),
    install_requires=[
        "Django",
        "djangorestframework",
        "python-decouple",
        "psycopg2-binary",
    ],
    extras_require={
        "testing": [
            "factory_boy",
            "jsonpath_ng",
            "pillow"
        ],
        "otherenv": [
            "numpy",
        ],
    },
    classifiers=[
        "Environment :: Web Environment",
        "Framework :: Django",
        "Framework :: Django :: 3.2",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: BSD License",
        "Operating System :: OS Independent",
        "Programming Language :: Python",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3 :: Only",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",
        "Programming Language :: Python :: 3.9",
        "Programming Language :: Python :: 3.10",
        "Topic :: Internet :: WWW/HTTP",
        "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
    ],
    python_requires=">=3.8",
)

Configure venv

powershell
python -m venv venv

./venv/Scripts/Activate

pip install -e . # Install the package without testing environment

pip install -e .[testing] # Install the package with testing environment
pip install -e .[testing,otherenv] # Install the package with testing environment

Good to know

References